FileSys Module

History

current 1.2 - 4th September 2024

version date comment
1.0 14/Feb/2013 Original code
1.1 11/Feb/2021 FileDir for returning list of files in a directory
1.2 04/Sep/2024 FileSyncToLastLine for synchronizing to the last line of formatted file

License

license: GNU GPL http://www.gnu.org/licenses/

This file is part of

MOSAICO -- MOdular library for raSter bAsed hydrologIcal appliCatiOn.

Copyright (C) 2011 Giovanni Ravazzani

Module Description

This module is designed to provide basic file and directory management and system operations for Windows and Linux based operating systems. For setting operating system, code pre processing (FPP) is used



Variables

Type Visibility Attributes Name Initial
integer, public, parameter :: UNIX = 2
integer, public, parameter :: WIN32 = 1

Functions

public function CurrentDir() result(cwd)

return current directory

Arguments

None

Return Value character(len=1000)

public function DirExists(dir) result(exists)

returns TRUE if directory exists

Arguments

Type IntentOptional Attributes Name
character(len=*), intent(in) :: dir

Return Value logical

public function FileExists(file) result(exists)

returns TRUE if file exists

Arguments

Type IntentOptional Attributes Name
character(len=*), intent(in) :: file

Return Value logical

public function GetOS() result(os)

get operating system

Arguments

None

Return Value integer


Subroutines

public subroutine DirDelete(dir)

delete a directory

Arguments

Type IntentOptional Attributes Name
character(len=*), intent(in) :: dir

public subroutine DirList(dir, list, nfiles, filext)

return a list of files in a directory

Arguments

Type IntentOptional Attributes Name
character(len=*), intent(in) :: dir
character(len=*), intent(out) :: list
integer(kind=short), intent(out) :: nfiles
character(len=*), intent(in), optional :: filext

public subroutine DirNew(dir)

create a new directory

Arguments

Type IntentOptional Attributes Name
character(len=*), intent(in) :: dir

public subroutine DirRename(dir, dir2)

rename a directory

Arguments

Type IntentOptional Attributes Name
character(len=*), intent(in) :: dir
character(len=*), intent(in) :: dir2

public subroutine FileDelete(file)

delete a file

Arguments

Type IntentOptional Attributes Name
character(len=*), intent(in) :: file

public subroutine FileNew(file)

create a new text file

Arguments

Type IntentOptional Attributes Name
character(len=*), intent(in) :: file

public subroutine FileRename(file, file2)

rename a file. If renamed file already exists it is not overwritten and warning is raised.

Arguments

Type IntentOptional Attributes Name
character(len=*), intent(in) :: file
character(len=*), intent(in) :: file2

public subroutine FileSyncToLastLine(fileUnit, blanks)

synchronize to the last line of formatted file

Arguments

Type IntentOptional Attributes Name
integer(kind=short), intent(in) :: fileUnit

unit of file to sync

integer(kind=short), intent(in) :: blanks

number of blank lines to add

public subroutine KeepLines(fileUnit, lines, pos, header)

Erase lines except the number specified as argument. pos defines wheter kept lines are counted starting from the beginning or from the end of file. Optional argument header defines number of lines at the beginning of the file to be considered as header. Header lines are never deleted. Manipulated file is supposed to be already opened.

Arguments

Type IntentOptional Attributes Name
integer(kind=short), intent(in) :: fileUnit
integer(kind=short), intent(in) :: lines
character(len=*), intent(in) :: pos

possible value: first, last

integer(kind=short), intent(in), optional :: header